package com.school.vo;

import java.util.HashMap;
import java.util.Map;

/**
 * 统一结果返回类
 */
public class R extends HashMap<String, Object> {
    private static final String CODE = "code";
    private static final String MESSAGE = "message";
    private static final String DATA = "data";

    public R() {
    }

    public static R ok() {
        R r = new R();
        r.put(CODE, "0");
        r.put(MESSAGE, "成功");
        r.put(DATA, null);
        return r;
    }

    public static R ok(String message, Object data) {
        R r = new R();
        r.put(CODE, "0");
        r.put(MESSAGE, message);
        r.put(DATA, data);
        return r;
    }

    public static R ok(Object data) {
        R r = new R();
        r.put(CODE, "0");
        r.put(MESSAGE, "成功");
        r.put(DATA, data);
        return r;
    }

    public static R ok(String message) {
        R r = new R();
        r.put(CODE, "0");
        r.put(MESSAGE, message);
        r.put(DATA, null);
        return r;
    }


    public static R err() {
        R r = new R();
        r.put(CODE, "-1");
        r.put(MESSAGE, "错误");
        r.put(DATA, null);
        return r;
    }

    public static R err(String message, Object data) {
        R r = new R();
        r.put(CODE, "-1");
        r.put(MESSAGE, message);
        r.put(DATA, data);
        return r;
    }

    public static R err(String message) {
        R r = new R();
        r.put(CODE, "-1");
        r.put(MESSAGE, message);
        r.put(DATA, null);
        return r;
    }

    public static R err(Object data) {
        R r = new R();
        r.put(CODE, "-1");
        r.put(MESSAGE, "错误");
        r.put(DATA, data);
        return r;
    }

    public static R build(int code, String message, Object data) {
        R r = new R();
        r.put(CODE, code);
        r.put(MESSAGE, message);
        r.put(DATA, data);
        return r;
    }

}